package com.runen.wnhz.runen.ui.adapter.puadapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.runen.wnhz.runen.R;
import com.runen.wnhz.runen.bean.UserStarScoreBean;
import com.runen.wnhz.runen.ui.adapter.puadapter.UserStarScoreRecyclerAdapter.ViewHolder;
import com.runen.wnhz.runen.widget.coustomview.CircleImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class UserStarScoreRecyclerAdapter extends RecyclerView.Adapter<ViewHolder> {

    private Context context;

    private List<UserStarScoreBean.DataBean.ListBean> listBeanList;

    public UserStarScoreRecyclerAdapter(Context context, List<UserStarScoreBean.DataBean.ListBean> listBeanList) {
        this.context = context;
        this.listBeanList = listBeanList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView = LayoutInflater.from(context).inflate(R.layout.user_star_item_layout, viewGroup, false);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {
        UserStarScoreBean.DataBean.ListBean listBean = listBeanList.get(position);
        Glide.with(context).load(listBean.getHead_img()).into(viewHolder.score_userHeadImg);
        viewHolder.score_userName.setText(listBean.getUsername());
        viewHolder.text_starTime.setText(listBean.getAddtime());
        viewHolder.rb_star.setRating(Float.parseFloat(listBean.getStar()));
        viewHolder.text_startContent.setText(listBean.getContent());
    }

    @Override
    public int getItemCount() {
        if(listBeanList != null){
            return listBeanList.size();
        }else{
            return 0;
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        @BindView(R.id.score_userHeadImg)
        CircleImageView score_userHeadImg;

        @BindView(R.id.score_userName)
        TextView score_userName;

        @BindView(R.id.rb_star)
        RatingBar rb_star;

        @BindView(R.id.text_starTime)
        TextView text_starTime;

        @BindView(R.id.text_startContent)
        TextView text_startContent;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
